<script>
	import store from 'store/index.js';
	import { mapGetters} from 'vuex';
    import { toLogin} from '@/libs/login.js';
	import Cache from './utils/cache';
	import { wechatAutoLogin } from "@/api/api.js"
	import {
		LOGIN_STATUS,
		USER_INFO,
		EXPIRES_TIME,
		STATE_R_KEY
	} from './config/cache';
	export default {
		globalData: {
			spid: 0,
			code: 0,
			isLogin: false,
			userInfo: {},
			MyMenus: [],
			globalData: false,
			isIframe: false,
			tabbarShow: true,
			windowHeight: 0
		},
		computed: mapGetters(['isLogin']),
		data() {  
			return {  
				amapPlugin: null,  
				key: '8ee2fa341efe9d4e3dcc4ea8449bed74',  
				weather: {  
					hasData: false,  
					data: []  
				} ,
				code: ''
			}  
		},

		
	  onLaunch: function(option) {
		  
		    console.log(this.$u.config.version);

		

		var that = this
		
		
		// 小程序更新
		const updateManager = wx.getUpdateManager();
			
		updateManager.onCheckForUpdate(function(res) {
			// 请求完新版本信息的回调
		});
		
		updateManager.onUpdateReady(function() {
			wx.showModal({
				title: '更新提示',
				content: '新版本已经准备好，是否重启应用？',
				success: function(res) {
					if (res.confirm) {
						// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
						updateManager.applyUpdate();
					}
				}
			});
		});
		
		updateManager.onUpdateFailed(function() {
			return that.Tips({
				title: '新版本下载失败'
			});
		});
		
	
		
		// 获取导航高度；
		uni.getSystemInfo({
			success: function(res) {
				that.globalData.navHeight = res.statusBarHeight * (750 / res.windowWidth) + 91;
			}
		});
		
		// #ifdef MP
		wx.login({
		  success (res) {
		    if (res.code) {
				wechatAutoLogin({
					opcode: res.code
				})
				.then(res => {
					console.log(123,res)
					that.$store.commit('LOGIN', {
						token: res.token,
					}); 
					var userInfo = res.user;
					that.$store.commit('SETUID', userInfo.id);
					that.$store.commit('UPDATE_USERINFO', userInfo);
				})
				.catch(err => {
					uni.hideLoading();
					console.log('err', err)
				});
				
				
		    } else {
		      console.log('登录失败！' + res.errMsg)
		    }
		  }
		})
		// #endif

		
		 },
		 methods:{
			 
		 },
		onShow: function() {
			
			console.log('App Show')
			
		
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	
	/*每个页面公共css */
	page{
			background-color: #FFFFFF;
		}
		/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
		@import "@/uni_modules/uview-ui/index.scss";
		/*每个页面公共css */
		@import "./common.css";
		
		@import './static/iconfont/iconfont.css';
		
		@import './static/iconfont/qsbs_iconfont/iconfont.css';
		@import url('@/plugin/emoji-awesome/css/google.min.css');
		// @import url('@/plugin/animate/animate.min.css');
		@import 'static/css/base.css';
		// @import 'static/css/guildford.css';
		@import 'static/css/style.scss';
		/* 解决小程序和app滚动条的问题 */
		/* #ifdef MP-WEIXIN || APP-PLUS */
		::-webkit-scrollbar {
		display: none;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
		color: transparent;
		}
		/* #endif */
		
		/* 解决H5 的问题 */
		/* #ifdef H5 */
		uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
		/* 隐藏滚动条，但依旧具备可以滚动的功能 */
		display: none;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
		color: transparent;
		}
		/* #endif */
		
		
		
		/* 条件编译，仅在H5平台生效 */
		// #ifdef H5
		body::-webkit-scrollbar,
		html::-webkit-scrollbar {
			display: none;
		}
		
		// #endif
		view {
			box-sizing: border-box;
		}
		
		.bg-color-red {
			background-color: #E93323;
		}
		
		.syspadding {
			padding-top: var(--status-bar-height);
		}
		
		.flex {
			display: flex;
		}
		
		.uni-scroll-view::-webkit-scrollbar {
			/* 隐藏滚动条，但依旧具备可以滚动的功能 */
			display: none
		}
		
		::-webkit-scrollbar {
			width: 0;
			height: 0;
			color: transparent;
		}

</style>
